package com.linxz.ui.spraycarview;


import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;


public class SprayItemData extends MutableLiveData<List<SprayItem1>> {
    public SprayItemData() {
        super();
        String json="[\n" + "    {\n" + "        \"title\":\"车头车尾\",\n" + "        \"list\":[\n" + "            {\n" + "                \"title\":\"前保险杠\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":17\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":18\n" + "                    }\n" + "                ],\n" + "                \"id\":\"1\"\n" + "            },\n" + "            {\n" + "                \"title\":\"后保险杠\",\n" + "                \"direction\":3,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":19\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":20\n" + "                    }\n" + "                ],\n" + "                \"id\":\"2\"\n" + "            },\n" + "            {\n" + "                \"title\":\"前车盖\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":21\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":22\n" + "                    }\n" + "                ],\n" + "                \"id\":\"3\"\n" + "            },\n" + "            {\n" + "                \"title\":\"后车盖\",\n" + "                \"direction\":3,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":23\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":24\n" + "                    }\n" + "                ],\n" + "                \"id\":\"4\"\n" + "            }\n" + "        ],\n" + "        \"id\":null\n" + "    },\n" + "    {\n" + "        \"title\":\"车左侧\",\n" + "        \"list\":[\n" + "            {\n" + "                \"title\":\"左前翼子板\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":33\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":34\n" + "                    }\n" + "                ],\n" + "                \"id\":\"5\"\n" + "            },\n" + "            {\n" + "                \"title\":\"左后翼子板\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":31\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":32\n" + "                    }\n" + "                ],\n" + "                \"id\":\"6\"\n" + "            },\n" + "            {\n" + "                \"title\":\"左前车门\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":35\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":36\n" + "                    }\n" + "                ],\n" + "                \"id\":\"7\"\n" + "            },\n" + "            {\n" + "                \"title\":\"左后车门\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":37\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":38\n" + "                    }\n" + "                ],\n" + "                \"id\":\"8\"\n" + "            },\n" + "            {\n" + "                \"title\":\"左后视镜\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":39\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":40\n" + "                    }\n" + "                ],\n" + "                \"id\":\"9\"\n" + "            },\n" + "            {\n" + "                \"title\":\"左裙边\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":41\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":42\n" + "                    }\n" + "                ],\n" + "                \"id\":\"10\"\n" + "            }\n" + "        ],\n" + "        \"id\":null\n" + "    },\n" + "    {\n" + "        \"title\":\"车右侧\",\n" + "        \"list\":[\n" + "            {\n" + "                \"title\":\"右前翼子板\",\n" + "                \"direction\":1,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":51\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":52\n" + "                    }\n" + "                ],\n" + "                \"id\":\"11\"\n" + "            },\n" + "            {\n" + "                \"title\":\"右后翼子板\",\n" + "                \"direction\":1,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":49\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":50\n" + "                    }\n" + "                ],\n" + "                \"id\":\"12\"\n" + "            },\n" + "            {\n" + "                \"title\":\"右前车门\",\n" + "                \"direction\":1,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":53\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":54\n" + "                    }\n" + "                ],\n" + "                \"id\":\"13\"\n" + "            },\n" + "            {\n" + "                \"title\":\"右后车门\",\n" + "                \"direction\":1,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":55\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":56\n" + "                    }\n" + "                ],\n" + "                \"id\":\"14\"\n" + "            },\n" + "            {\n" + "                \"title\":\"右后视镜\",\n" + "                \"direction\":1,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":57\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":58\n" + "                    }\n" + "                ],\n" + "                \"id\":\"15\"\n" + "            },\n" + "            {\n" + "                \"title\":\"右裙边\",\n" + "                \"direction\":1,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":59\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":60\n" + "                    }\n" + "                ],\n" + "                \"id\":\"16\"\n" + "            }\n" + "        ],\n" + "        \"id\":null\n" + "    },\n" + "    {\n" + "        \"title\":\"其他\",\n" + "        \"list\":[\n" + "            {\n" + "                \"title\":\"车顶\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":63\n" + "                    },\n" + "                    {\n" + "                        \"title\":\"钣金喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":64\n" + "                    }\n" + "                ],\n" + "                \"id\":\"17\"\n" + "            },\n" + "            {\n" + "                \"title\":\"全车喷漆\",\n" + "                \"direction\":0,\n" + "                \"list\":[\n" + "                    {\n" + "                        \"title\":\"喷漆\",\n" + "                        \"list\":null,\n" + "                        \"id\":65\n" + "                    }\n" + "                ],\n" + "                \"id\":\"18\"\n" + "            }\n" + "        ],\n" + "        \"id\":null\n" + "    }\n" + "]";
        List<SprayItem1> data=new Gson().fromJson(json,new TypeToken<List<SprayItem1>>(){}.getType());
        setValue(data);
    }
    public void refresh(){
        setValue(getValue());
    }


    public void  checkAllSpray(){
        List<SprayItem1> data=getValue();
        if(data!=null){
            for(SprayItem1 item1:data){
                for(SprayItem2 item2:item1.getList()){
                    if(!Constant.ID_ALL.equals(item2.getId())){
                        item2.checkNull();
                    }else {
                        item2.checkSpray();
                    }
                }
            }
        }
    }

    public void  checkNull(){
        List<SprayItem1> data=getValue();
        if(data!=null){
            for(SprayItem1 item1:data){
                for(SprayItem2 item2:item1.getList()){
                    item2.checkNull();
                }
            }
        }
    }

    public void  checkSprayItems(){
        List<SprayItem1> data=getValue();
        if(data!=null){
            for(SprayItem1 item1:data){
                for(SprayItem2 item2:item1.getList()){
                    if(!Constant.ID_ALL.equals(item2.getId())){
                        item2.checkSpray();
                    }else {
                        item2.checkNull();
                    }
                }
            }
        }
    }
}
